package com.ymttest.business.service;

import java.util.ArrayList;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONObject;

import com.ymatou.app.parameter.LiveInfoBean;
import com.ymatou.app.parameter.LiveProductIdsBean;
import com.ymatou.app.service.LiveInfoCall;
import com.ymatou.app.service.LiveProductIdsCall;
import com.ymatou.iapi.live.parameter.GetSellerCouponListBean;
import com.ymatou.iapi.live.service.GetSellerCouponListCall;
import com.ymt.core.tool.Logger;
import com.ymttest.utils.TestDataManager;

public class BuyerCallService {
	
	private static SellerCallService sellerCallService = null;
	private static LiveProductIdsBean liveProductidsBean = null;
	private static LiveProductIdsCall liveProductIdsCall = null;
	private static LiveInfoBean liveInfoBean = null;
	private static LiveInfoCall liveInfoCall = null;
	private static GetSellerCouponListBean getSellerCouponListBean = new GetSellerCouponListBean();
	private static GetSellerCouponListCall getSellerCouponListCall = new GetSellerCouponListCall();
	
	private int activityId = 0;
	
	public BuyerCallService() {
		
	}
	
	public BuyerCallService(String userName, String password) {
		sellerCallService = new SellerCallService(userName, password);
		liveProductidsBean = new LiveProductIdsBean();
		liveProductIdsCall = new LiveProductIdsCall();
		liveInfoBean = new LiveInfoBean();
		liveInfoCall = new LiveInfoCall();
	}
	
	/**
	 * 获取正在直播的商品列表
	 */
	@SuppressWarnings("static-access")
	public JSONArray getProductIdsInProgress() {
		
		try {
			sellerCallService.createActivity();
			
			activityId = sellerCallService.getActivityInProgress();
			
			Logger.comment("添加三个商品");
			sellerCallService.createProduct(activityId, 3);
			
			Thread thread = Thread.currentThread();
			thread.sleep(15000);
			
			Logger.comment("直播验证");
			liveProductidsBean.setLiveid(activityId);
			liveProductidsBean.setBrandids(new ArrayList<Integer>());
			liveProductidsBean.setCategoryids(new ArrayList<Integer>());
			
			liveProductIdsCall.setData(liveProductidsBean);
			
			liveProductIdsCall.callService();
			
			return liveProductIdsCall.getLiveProductList();
		} catch(Exception e) {
			Logger.fail(e);
			return new JSONArray();
		}
	}
	
	/**
	 * 获取直播信息
	 */
	public JSONObject getLiveInfo() {
		
		try {
			sellerCallService.createActivity();
			
			activityId = sellerCallService.getActivityInProgress();
			
			Logger.comment("添加商品");
			sellerCallService.createProduct(activityId);
			
			Logger.comment("直播验证");
			liveInfoBean.setLiveid(activityId);
			
			liveInfoCall.setData(liveInfoBean);
			liveInfoCall.callService();			
			
			return liveInfoCall.getLiveInfo();
			
		} catch(Exception e) {
			Logger.fail(e);
			return new JSONObject();
		}
	}
	
//	/***
//	 * 获取买手的优惠券列表
//	 * @param sellerId（买手ID）
//	 * @return JSONArray（优惠券列表）
//	 * @throws Exception
//	 */
//	@SuppressWarnings("rawtypes")
//	public JSONArray getSellerCouponList(int sellerId) throws Exception {
//		JSONArray array = null;
//		
//		Map user = UserCallService.registerUser(TestDataManager.getEmail(), null,null);
//		 
//		int userId = (Integer)user.get("userId");
//		getSellerCouponListBean.setSellerId(sellerId);
//		getSellerCouponListBean.setUserId(userId);
//		
//		getSellerCouponListCall.setData(getSellerCouponListBean);
//		getSellerCouponListCall.callService();
//		array = new JSONArray(getSellerCouponListCall.getCouponsList().toString());
//		return array;
//	}
}
